package com.demo.thread.semaphore.test1;

import java.util.concurrent.Semaphore;

/**
 * @author : YU.TAN
 * @date : 2021/11/9 18:07
 */
public class Service {

    private Semaphore semaphore = new Semaphore(2);

    public void testMethod() {
        try {
            semaphore.acquire();
            System.out.println(Thread.currentThread().getName() + "-begin timer:" + System.currentTimeMillis());

            Thread.sleep(100);
            System.out.println(Thread.currentThread().getName() + "-end timer:" + System.currentTimeMillis());

            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
